<?php
/**
 * 中间部分
 */

class Admin_Page_Main extends Admin_Page_Abstract
{
    private $db;
    private function loadDb()
    {
        $this->db = Db_Admin::instance();
    }
    public function validate(ME_Request $input, ME_Response $output)
    {
        $input->doJump = true;
        $adminInfo = Libs_UcUser::getAdminLoginInfo($input,$output);
        $input->adminUser = $output->adminUser = $adminInfo[0];
        $output->appId    =
        $input->appId     = (int)$input->get("appId");
        return true;
    }

    public function doDefault(ME_Request $input, ME_Response $output)
    {
        $this->loadDb();

        //频道信息
        $classInfo = $this->loadCache("Cms_Class",array('appId'=>$input->appId));
        ksort($classInfo);
        $output->classInfo = $classInfo;
        //获得文章的情况
        $sql = "select count('x') cnt ,status from cms_document_title_1 group by status";
        $tmCntArr = $this->db->getAll($sql);
        $outArt = array();
        if($tmCntArr){
            foreach($tmCntArr as $art){
                $outArt[$art["status"]] = $art["cnt"];
            }
        }
        $output->docCntArr = $outArt;


        $yestodayStr = date("Y-m-d",strtotime("-1 day"));
        $yestodayStr = $yestodayStr . ' 00:00:00';
        $yestodaytm = strtotime($yestodayStr);
        $todaytm =  strtotime(date("Y-m-d"). ' 00:00:00');


        //每个人的文章情况
        $fromDate = '2011-7-12 00:00:01';
        $fromtm = strtotime($fromDate);
        $sql = "select count('x') cnt,username from cms_document_title_1 where status=3  and datetm >  {$fromtm} group by username";
        //echo $sql;exit;
        $tmpArr = $this->db->getAll($sql);
        $authAllArt = array();
        if($tmpArr){
            foreach($tmpArr as $art){
                $authAllArt[$art["username"]] = $art["cnt"];
            }
        }
        $output->authAllArt = $authAllArt;


        $sql = "select count('x') cnt,username from cms_document_title_1 where status=3  and datetm >  {$todaytm} group by username";
        $tmpArr = $this->db->getAll($sql);
        $authTodayArt = array();
        if($tmpArr){
            foreach($tmpArr as $art){
                $authTodayArt[$art["username"]] = $art["cnt"];
            }
        }
        $output->authTodayArt = $authTodayArt;

        $sql = "select count('x') cnt,username from cms_document_title_1 where status=3  and datetm >  {$yestodaytm} group by username";
        $tmpArr = $this->db->getAll($sql);
        $authYestodyArt = array();
        if($tmpArr){
            foreach($tmpArr as $art){
                $authYestodyArt[$art["username"]] = $art["cnt"];
            }
        }
        $output->authYestodyArt = $authYestodyArt;

        //获得每个频道的编辑情况信息

        //今天的文章
        $todaySql = "select count('x') cnt,classId  from cms_document_title_1 where status=3  and datetm >  {$todaytm} group by classId";
        $tmCntArr = $this->db->getAll($todaySql);
        $todayArt = array();
        if($tmCntArr){
            foreach($tmCntArr as $art){
                $todayArt[$art["classId"]] = $art["cnt"];
            }
        }
        $output->todayArt = $todayArt;
        
        //昨天的文章
        $yestodaySql = "select count('x') cnt,classId  from cms_document_title_1 where status=3  and datetm >  {$yestodaytm} and datetm < {$todaytm} group by classId";
        $tmCntArr = $this->db->getAll($yestodaySql);
        $yestodayArt = array();
        if($tmCntArr){
            foreach($tmCntArr as $art){
                $yestodayArt[$art["classId"]] = $art["cnt"];
            }
        }
        $output->yestodayArt = $yestodayArt;

        //读取收录情况
        $output->shouluTxt = ME_File::get(HTML_PATH . "/inc/{$input->appId}_shoulu.txt");

        //百度来访情况
        $output->baidulog = ME_File::get("/usr/nginx/logs/baidulog/log.txt");
        $output->setTemplate("Main");
    }

}
